import 'package:flutter/material.dart';
import 'package:love_app/providers/love_grallery.dart';
import 'package:love_app/providers/love_record_provider.dart';
import 'package:provider/provider.dart';
import 'package:yin_drag_sacle/core/drag_scale_widget.dart';

// 展示每个item的所有图片
class ShowImageUI extends StatefulWidget {
  final int itemId; // item对应的id
  final int index;

  ShowImageUI({@required this.itemId, @required this.index});

  @override
  _ShowImageUIState createState() => _ShowImageUIState();
}

class _ShowImageUIState extends State<ShowImageUI> {
  @override
  Widget build(BuildContext context) {
    LoveRecordProvider loveRecordProvider =
        Provider.of<LoveRecordProvider>(context, listen: false);
    List<String> imagesList =
        loveRecordProvider.getImagesList(widget.itemId); // 根据id获取对应的图片集
    PageController _pageController =
        PageController(initialPage: widget.index); // 默认第一张显示
    return Scaffold(
      backgroundColor: Colors.black,
      body: Container(
        child: PageView.builder(
          itemCount: imagesList.length,
          controller: _pageController,
          itemBuilder: (BuildContext context, int index) {
            return InkWell(
              onTap: () {
                Navigator.pop(context);
              },
              child: DragScaleContainer(
                child: Image.network(
                  imagesList[index],
                  fit: BoxFit.fitWidth,
                ),
              ),
            );
          },
        ),
      ),
    );
  }
}

// 根据index显示图片
class ShowGralleyAll extends StatelessWidget {
  final int index; // 默认要现在的图片对应的索引

  const ShowGralleyAll({Key key, this.index}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    LoveGralleryProvider loveGralleryProvider =
        Provider.of<LoveGralleryProvider>(context, listen: false); // 相册共享数据
    PageController _pageController = PageController(initialPage: index);
    return Scaffold(
      backgroundColor: Colors.black,
      body: Container(
        child: PageView.builder(
          itemCount: loveGralleryProvider.gralleryList.length,
          controller: _pageController,
          itemBuilder: (BuildContext context, int index) {
            return InkWell(
              onTap: () {
                Navigator.pop(context);
              },
              child: DragScaleContainer(
                child: Image.network(
                  loveGralleryProvider.gralleryList[index],
                  fit: BoxFit.fitWidth,
                ),
              ),
            );
          },
        ),
      ),
    );
  }
}
